% $Id: FileLoader.m 7 2009-01-27 12:46:40Z Jie.Bao $

classdef FileLoader
%ANALYZER Main Loader class for 1 file. 
%   Opens 1 log file and handles all of the analysis. This is the only file
%   that contains the data, and knows which data to send to any analysis
%   script. Constructor needs a directory, a file name, and an
%   ExperimentSetup object. Main functions include EasyPlot(),
%   GetStatisticsCSV(), GetTableHeadings().
%   

   properties
       FileName = '';
       Directory = '';
       Data;
       Length;
       
       Floor;
       Region;
       
       MetaData;
       
       Experiment;
       
       %is used to determine if this file is a slice from an exploration
       %trial, and if so what the task was in that exploration trial.
       IsCut = 0;
       CutType = 0;
       
       
       %Meta Information for the graphs
       Subject = '';
       Condition = '';
       Trial = '';
       Item = '';
       
       
       %CONSTANTS FOLLOW FROM HERE
       FileFormat = '%f,%f,%f,%f,%f,%f,%f';
       MarketFileFormat = '%f %f %f %f';
       MapDirectory = '../';
       STOPS_COLOR_MULTIPLIER = 100;
       
       %The other analyzers
       PathA;
       StopsA;
       VelocityA;
       DistanceA;
       TurnA;
       PointingA;
       AreaCoveredA;
       
   end

   methods
       %CONSTRUCTOR
       %Needs a directory to read the file from, it also needs a file name.
       %Finally it needs an ExperimentSetup object to determine different
       %constants and settings such as where to find maps and other data
       %needed. 
       function obj = FileLoader(directory, file, experiment)
           %Save location information about the file
           obj.Directory = directory;
           obj.FileName = file;
           
           %Save the experiment setup to have access to it later
           obj.Experiment = experiment;

           %Read the log data and save all the columns.
           obj = obj.OpenData();
           
           %analyses teh file name to determine condition, subject, and
           %trial number
           %obj = obj.SetMeta();
           
           %open OBJ formatted floor plan. obj file found in path specified
           %by the ExperimentSetup. This floor plan will be used to output
           %the maze/surroundings
           %if strcmp(obj.Experiment.ExpType, 'PathChoice')
           %    obj.Floor = OBJFloorLoader([obj.Experiment.MapDirectory ...
           %                                '/school8.obj']);
           %elseif strcmp(obj.Experiment.ExpType, 'Supermarket')

           %else
           %    obj.Floor = OBJFloorLoader([obj.Directory ...
           %                            '/' ...
           %                            obj.MapDirectory ...
           %                            obj.GetFileName ...
           %                            '.obj']);
           %end
           
           %open OBJ formatted region listing and locations.
           %these are also found in the path specified throught the
           %ExperimentSetup. This is used to show different regions of the
           %map on the plots, as well as to determine what region a user is
           %in, how long they are in that region for, and their path
           %analysis
           %obj.Region = OBJRegionLoader([obj.Directory ...
           %                            '/' ...
           %                            obj.MapDirectory ...
           %                            obj.GetFileName ...
           %                            '.region' ...
           %                            '.obj']);
           
           obj = obj.Initialize();
       end
       
       %function that creates all the analyzers and processes everything.
       %this is used mainly for split, when items are copies but the data
       %is segmented so all the analyzers have to be re-run
       function  obj = Initialize(obj)
           clear PathA
           clear StopsA
           clear VelocityA
           clear DistanceA
           clear TurnA
           clear PointingA
           clear AreaCoveredA
           
           obj.PathA = PathAnalyzer();
           obj.PathA.X = obj.Data(:,obj.Experiment.X);
           obj.PathA.Y = obj.Data(:,obj.Experiment.Y);
           %obj.PathA.Z = obj.Data(:,obj.Experiment.Z);
           obj.PathA.T = obj.Data(:,obj.Experiment.T);           
           
           
           %Create a stops analyzer that determines length and location of
           %all stops
           %obj.StopsA = StopsAnalyzer(obj.Data(:,obj.Experiment.X), ...
           %                           obj.Data(:,obj.Experiment.Y), ...
           %                           obj.Data(:,obj.Experiment.Z));
           obj.StopsA = StopsAnalyzer(obj.Data(:,obj.Experiment.T), ...
                                      obj.Data(:,obj.Experiment.X), ...
                                      obj.Data(:,obj.Experiment.Y));
           
           %create a velocity analyzer to give different statistics about
           %the movement of the subject over their trial
           %obj.VelocityA = VelocityAnalyzer(obj.Data(:,obj.Experiment.X), ...
           %                                 obj.Data(:,obj.Experiment.Y), ...
           %                                 obj.Data(:,obj.Experiment.Z), ...
           %                                 obj.Data(:,obj.Experiment.T));
           obj.VelocityA = VelocityAnalyzer(obj.Data(:,obj.Experiment.T), ...
                                            obj.Data(:,obj.Experiment.X), ...
                                            obj.Data(:,obj.Experiment.Y));
           
                                        
           %create a velocity analyzer to give different statistics about
           %the distance covered by subject over their trial                             
           %obj.DistanceA = DistanceAnalyzer(obj.Data(:,obj.Experiment.X), ...
           %                                 obj.Data(:,obj.Experiment.Y), ...
           %                                 obj.Data(:,obj.Experiment.Z));
           obj.DistanceA = DistanceAnalyzer(obj.Data(:,obj.Experiment.X), ...
                                            obj.Data(:,obj.Experiment.Y));
                                        
           %create a heading analyzer to analyze the turns at each stop
           %point which the user performs.
           %obj.TurnA =      HeadingAnalyzer(obj.Data(:,obj.Experiment.X), ...
           %                                 obj.Data(:,obj.Experiment.Y), ...
           %                                 obj.Data(:,obj.Experiment.Z), ...
           %                                 -obj.Data(:,obj.Experiment.H));
                                        
           obj.PointingA = PointingAnalyzer;
           obj.PointingA.X = obj.Data(length(obj.Data(:,1)), obj.Experiment.X);
           obj.PointingA.Y = obj.Data(length(obj.Data(:,1)), obj.Experiment.Y);
           %obj.PointingA.Z = obj.Data(length(obj.Data(:,1)), obj.Experiment.Z);
           obj.PointingA.H = obj.Data(length(obj.Data(:,1)), obj.Experiment.H);
           
           %obj.AreaCoveredA = AreaCoveredAnalyzer(obj.Region, ...
           %                                       obj.Data(:,obj.Experiment.X), ...
           %                                       obj.Data(:,obj.Experiment.Y), ...
           %                                       obj.Data(:,obj.Experiment.Z)); 
       end
       %MAIN FUNCTIONS
       
       %main plotting function. Plots the floorplan, the path, and the
       %stops. holds the plot between each call so it does not get
       %overwritten, but actually places one on top of the other.
       function obj = EasyPlot(obj)
           
           figure
           
           %load the floor plan
           %obj.Region.Plot();
           obj.Experiment.Floor.Plot(obj.Experiment.Scale, ...
               obj.Experiment.TransformX, obj.Experiment.TransformY);
           
           %Plot the full path
           obj.PathA.Plot(1,0,0);
           Title = regexprep(obj.FileName, '_', '\\_');
           title(Title);
           
           %plot the stops
           %obj.StopsA.Plot(1);    
           
           %subplot(222);
           %obj.VelocityA.Plot;
           
           %subplot(223);
           %obj.VelocityA.MakeHistogram;              

       end    
       
       function [x] = GetMyStatistics(this)
           x = [this.Subject ',' this.Item];
           x = [x ',' num2str(this.DistanceA.GetLength)];
           x = [x ',' num2str(this.StopsA.TotalNumber)];
           x = [x ',' num2str(this.StopsA.TotalDuration)];
           x = [x '\n'];
       end
       
       %output a line of all the statistcs for this log file. All values
       %are seperated by commas. See the heading function to see what all
       %of these statistics are.
       function [x] = GetStatisticsCSV(this)
            x = '';
           
            x = [x this.GetFileInformation()];
            
            %trial length
            x = [x ',' num2str(length(this.Data(:,1))/10)];
            
            %total distance
            x = [x ',' num2str(this.DistanceA.GetLength())];
            
            %avg velocity
            x = [x ',' num2str(this.VelocityA.AverageVelocity())];
            
            %avg moving velocity
            x = [x ',' num2str(this.VelocityA.MovingAverage())];
            
            %time at full speed   
            x = [x ',' num2str(this.VelocityA.GetFullSpeedTime())];
            
            %time stopped
            x = [x ',' num2str(this.VelocityA.GetStopTime())];
            
            %number of stops
            x = [x ',' num2str(length(this.StopsA.Duration))];
            
            %stop time
            x = [x ',' num2str(sum(this.StopsA.Duration))];
            
           
            sumS = 0;
            sumR = 0;
            for i=1:length(this.TurnA.StopsL)
                sumS = sumS+ this.TurnA.StopsL{i}.TotalSweep;
                sumR = sumR+ this.TurnA.StopsL{i}.Range;
            end
            
             %total angular sweep
            x = [x ',' num2str(sumS)];
            
            %total angular range
            x = [x ',' num2str(sumR)];
            
            %sweep to range ratio
            if sumS == 0 || sumR == 0
                x = [x ',' '1'];
            else
                x = [x ',' num2str(sumS - sumR)];
            end
            %room transfers
            %x = [x ','];
            %rList = this.Region.AnalyzePath(this.Data(:,this.Experiment.X), ...
            %                                this.Data(:,this.Experiment.Y)   );
            %for j=1:length(rList)
            %   x = [x '->' rList{j}]; 
            %end
            
            %output the correct angle pointing should have been at
            x = [x ',' num2str(this.PointingA.GetCorrectAngle())];

            %output the angle the person pointed towards
            x = [x ',' num2str(this.PointingA.H)];

            %output the pointing error
            x = [x ',' num2str(this.PointingA.GetHeadingAbsolute())];
            
            %next line
            x = [x '\n'];
       end
       
       
       %outputs the statistics for each region, things like duration and
       %such
       function x = GetRegionStatistics(this)
           x = '';
           
           [region, duration] = this.Region.AnalyzePath2(this.Data(:,2), ...
                                                         this.Data(:,3));
           %region
           for j=1:length(region)
               x = strcat(x, this.GetFileInformation());
                
                %output the region name
                x = strcat(x, ',');
                x = strcat(x, region(j));
                
                %output the duration in region
                x = strcat(x, ',');
                x = strcat(x, num2str(duration(j)/10));
               
                % newline
                x = strcat(x, ' \n');
           end
       end
       
       
       %outputs the statistics for eachs top. X,Y,Z, length, Sweep, Range
       function x = GetStopStatistics(this)
           x = '';
           
           for j=1:length(this.TurnA.StopsL)
                x = [x this.GetFileInformation()];
                
                %Stop X
                x = [x ',' num2str(this.TurnA.StopsL{j}.X)];
                
                %Stop Y
                x = [x ',' num2str(this.TurnA.StopsL{j}.Y)];
                
                %Stop Z
                x = [x ',' num2str(this.TurnA.StopsL{j}.Z)];
                
                %Stop Duration
                x = [x ',' num2str(length(this.TurnA.StopsL{j}.H)/10)];
                
                %stop Sweep
                x = [x ',' num2str(this.TurnA.StopsL{j}.TotalSweep)];
                
                %stop Range
                x = [x ',' num2str(this.TurnA.StopsL{j}.Range)];
                
                %ooutput the difference between the sweep and range
                dif = this.TurnA.StopsL{j}.TotalSweep- this.TurnA.StopsL{j}.Range;
                %look for rounding errors and take them to 0 to make it
                %easier to read the files
                if abs(dif)<.1
                    dif = 0;
                end
                x = [x ',' num2str(dif)];
               
                
                %newline
                x = [x '\n'];  
           end
       end
       
       %outputs the region covered statistics which say when (time, and
       %distance traveled) each region is discovered
       function x = GetAreaCoveredStatistics(this)
           x = '';
           
           for j=1:this.AreaCoveredA.Length
                x = [x this.GetFileInformation()];
                
                %regiion name
                x = [x ',' this.AreaCoveredA.Data{j,1}];
                
                %time the region was aproached at
                x = [x ',' num2str(this.AreaCoveredA.Data{j,2})];
                
                %Distance rtraveled to reach region
                x = [x ',' num2str(this.AreaCoveredA.Data{j,3})];
                
                %Percent area covered after this much distance
                x = [x ',' num2str(this.AreaCoveredA.Data{j,4})];
                
                %newline
                x = [x '\n ']; 
           end
           
       end
       
       %creates the first few columns which have subject number, task,
       %trial, maze and so on.
       function x = GetFileInformation(this)
            %subject
            x = '';
            x = [x this.Subject];

            %output full conditions
            x = [x ',' this.Condition];

            %numerical conditions
            if this.Condition(1) == 'I'|| this.Condition(1) == 'i'
                %maze
                x = [x ',' '0'];

                %ball Location
                x = [x ',' '0'];

                %task
                x = [x ',' '0'];                
            else
                %maze
                if this.Condition(1) == 'T'
                    x = [x ',' '1'];
                else
                    x = [x ',' '2'];
                end
                %ball Location
                x = [x ',' this.Condition(3)];

                %task
                if this.Condition(5) == 'S'
                    x = [x ',' '1'];
                else
                    x = [x ',' '2'];
                end
            end
            %trial
            x = [x ',' this.Trial];
            
            
            %is it a cut of the exploration
            x = [x ',' num2str(this.IsCut)];
            
            %if it is cut from exploration, what task was it cut from
            
            x = [x ',' num2str(this.CutType)];

       end
       
       %headings for the stop statistics
       function h = GetStopStatisticsHeadings(this)
           h = ['SubjectNumber,' ...
                'Condition,' ...
                'Maze,' ...
                'BallLocaton,' ...
                'Task,' ...
                'Trial,' ...
                'IsCut,' ...
                'CutType,' ...                
                'X,'...
                'Y,'...
                'Z,'...
                'Duration,'... 
                'TotalSweep,' ...
                'RangeOfTurn,'...
                'Sweep-Range \n'...
                ];
       end    
           
       %heading data for the CSV statistics. Lists what all the values
       %output are.
       function h = GetTableHeadings(this)
             h = ['SubjectNumber,' ...
                  'Condition,' ...
                  'Maze,' ...
                  'BallLocation,' ...
                  'Task,' ...
                  'Trial,' ...
                  'IsCut,' ...
                  'CutType,' ... 
                  'Duration(s),' ...
                  'TotalDistance,' ...
                  'AverageVelocity,' ...
                  'MovingVelocity,' ...
                  'TimeFullSpeed,' ...
                  'TimeStopped,' ...
                  'NumberOfstops,' ...
                  'StopDuration,' ...
                  'TotalAngularSweep,'...
                  'TotalAngularRange,' ...
                  'SweeptoRangeDiff,' ...
                  'CorrectAngle,'...
                  'PointingAngle,'...
                  'PointingError \n'...
                ];
       end
       
       %headings for the region statistics
       function h = GetRegionTableHeadings(this)
           h =   ['SubjectNumber,' ...
                  'Condition,' ...
                  'Maze,' ...
                  'BallLocation,' ...
                  'Task,' ...
                  'Trial,' ...
                  'IsCut,' ...
                  'CutType,' ... 
                  'Region,' ...
                  'Duration \n' ...
                  ];
       end
       
       %headings for teh area covered statistics
       function h = GetAreaCoveredTableHeadings(this)
           h =   ['SubjectNumber,' ...
                  'Condition,' ...
                  'Maze,' ...
                  'BallLocation,' ...
                  'Task,' ...
                  'Trial,' ...
                  'IsCut,' ...
                  'CutType,' ... 
                  'Region,' ...
                  'TimeReached,' ...
                  'DistanceReached,' ...
                  'AreaCovered \n' ...
                  ];
       end
           
       %performs a region analsis of the path. That is it goes through the
       %entire path the user performed, and figures out the sequence of
       %regions that were traversed during the path. Returns this list.
       function list = AnalyzePath(obj)
          list = obj.Region.AnalyzePath(obj.Data(:,obj.Experiment.X), ...
                                        obj.Data(:,obj.Experiment.Y)); 
       end
       
       %creates a histogram of the velocities used during this trial. this
       %is used to see if the user was stopped a lot, if they went at
       %average speeds, or if they went full speed all the time.
       function obj = AnalyzeVelocities(obj)                   
           obj.VelocityA.MakeHistogram();
       end
       
       %function to determine how long this log file spent in a specific
       %region. The region is of the format of a string. A string which
       %should b the name of an object from the obj file. Example 'Box01'
       function t = GetTimeInRegion(this, region)
           t = this.Region.GetTimeInRegion(region, this.Data(:,2), this.Data(:,3));
       end
       
       %Setter for the FileName
       function obj = set.FileName(obj, file)
         obj.FileName = file;
       end       
       
       %Setter for the Directory
       function obj = set.Directory (obj, dir)
           obj.Directory = dir;
       end
       
       %Setter for the FileFormat
       function obj = set.FileFormat(obj, format)
           obj.FileFormat = format;
       end
       
       function [td, av, dot, mv] = GetStatistics(obj)
           td = obj.DistanceA.GetLength();
           av = obj.VelocityA.AverageVelocity();
           dot = obj.DistanceA.GetLength()/length(obj.Data(:,1));
           mv = obj.VelocityA.MovingAverage();
       end
       
       function new = Split(this, len, withExp)
           
           %Create the empty splits file
           file = ['split_' num2str(len) '_' this.FileName];
           if ~exist([this.Directory '/splits'], 'dir');
               mkdir(this.Directory, 'splits');
           end           
           file = [this.Directory '/splits/' file];
           out = fopen(file,'w');   
           
           %write a csv file to represent the log
           for j=1:len
               line = [num2str(this.Data(j,1)) ',' ...
                       num2str(this.Data(j,2)) ',' ...
                       num2str(this.Data(j,3)) ',' ...
                       num2str(this.Data(j,4)) ',' ...
                       num2str(this.Data(j,5)) ',' ...
                       num2str(this.Data(j,6)) ',' ...
                       num2str(this.Data(j,7))     ...
                       '\n'
                      ];
                fprintf(out,line);
           end
           fclose(out);
           
           
           %Create a copy of thsi file with sub data
           new = this;
           
           %Copy data over
           new.Data = this.Data(1:len,:);
           
           %do analysis with new data
           new = new.Initialize();
           
           %set some new meta
           new.Trial = '0';
           new.Length = len;
           new.IsCut = 1;
           new.CutType = withExp;
           new.Condition = [new.Condition '_' num2str(len) '_' num2str(withExp)];
       end

       
       %PRIVATE FUNCTIONS
       
       %function to open the data and store it. 
       %this si where changes would be made if the data format were to
       %change. The actual format (comma seperated values, tab seperated
       %values, or whatever are in the ExperimentSetup file. This would
       %need to be changed if the order of columsn changes, or more columns
       %are added. see documentation for textread if needed.
       %ignores the first line because that is usually missing some
       %information and not interesting.
       function obj = OpenData(obj)
           if strcmp(obj.FileName,'') == 0
               file = [obj.Directory '/' obj.FileName]
               if strcmp(obj.Experiment.ExpType, 'PathChoice')
                    [t,x,y,z,h,r,p] = textread(file, obj.FileFormat, ...
                        'headerlines',1);
                    obj.Data = [t,x,y,z,h,r,p];
               elseif strcmp(obj.Experiment.ExpType, 'Supermarket')
                    [t,x,y,h] = textread(file, obj.Experiment.LogFormat, ...
                        'headerlines',1);
                    obj.Data = [t,x,y,h];
               end
           else
               error ('missing filename or directory');
           end
           obj.Length = length(obj.Data(:,1));
       end
             
       %used to determine what model file was used. This is used to later
       %determine which region or floor plan to open. The model name is
       %contained in the brackets of the file name, but before the event.
       %HOPEFULLY the only '.' in the filename is contained right before
       %teh file extension.
       function file = GetFileName(obj)
           %NAMING_FORMAT = ['(?<vpn>\w+)[(?<map>\w+).(?<extension>\w+)](?<date?\w+).csv|'...
           %                 '(?<vpn>\w+)[(?<map>\w+).(?<extension>\w+)[EVENT]](?<date?\w+).csv']
           begin = findstr(obj.FileName, '[');
           send  = findstr(obj.FileName, '.');
           string = obj.FileName;
           
           file = '';
           
           for i=0:length(string);
               if i>begin(1) && i<send(1);
                   file(length(file)+1) = string(i);
               end
           end
           
       end
       
       
       %obtains meta information from the file name. The format right now
       %is "SUBJECTNUMBER_CONDITION_TRIAL[........" The condition may
       %contain additional '_' to delimit say maze, ball location, or task
       %under our circumstances. Those values are used elsewhere. This is
       %general enough to handle other experiments.
       function obj = SetMeta(obj)           
           %file = java.lang.String(obj.FileName);
           %meta = file.substring(0, file.indexOf('['));
           meta = textscan(obj.FileName, '%*s%d%*s%d%*s', ...
               'delimiter', '_');
           
           %get the subject number
           %obj.Subject = char(meta.substring(0, meta.indexOf('_')));
           %meta = meta.substring(meta.indexOf('_')+1);
           obj.Subject = num2str(cell2mat(meta(2)));
           
           %get the conditions 
           %obj.Condition = char(meta.substring(0, meta.lastIndexOf('_')));
        
           %get the Trial Number
           %obj.Trial = char(meta.substring(meta.lastIndexOf('_')+1, meta.length()));
           
           % get the item number
           obj.Item = num2str(cell2mat(meta(1)));
           
       end
       
       %adds the meta information as the title of a plot. subject number,
       %condition, and trial.
       function AddMeta(obj)
           hold on;
           naming = ['Subject: ' obj.Subject  '--' obj.Condition ...
                     '-Trial:' obj.Trial];
           title(naming);
       end
       
       
       %saves the current plot. uses the ExperimentSetup to determine the
       %output path. If needed creates a subfolder for the subject number.
       %extra is used to tell what kind of plot is beign saved. a 'path'
       %will be saved ina  'path' subfolder, 'histograms' saved under
       %'histogram'. If additional plot types are created, just pass a
       %different value of extra and a new subfolder will be created.
       %Individual file names remain the same. 'Subject-condition-trial.jpg'
       function Save(obj, extra)
           if exist([obj.Experiment.OutPutDirectory '/' obj.Subject '/' extra], 'dir') ~= 7
               mkdir(obj.Experiment.OutPutDirectory, [obj.Subject '/' extra])
           end
           outfile = [obj.Experiment.OutPutDirectory '/' ...
                      obj.Subject '/' ...
                      extra '/' ...
                      obj.Subject '-' obj.Condition '-' obj.Trial '.jpeg'];
           print('-djpeg',outfile);
       end
       
      
       
       %plots the heading from the last heading in the file. This is the
       %part where we asked participants to point towards where they were
       %looking. This will plot a line along their line of sight.
       function PlotHeading(obj)
           [final, pos] = obj.GetFinalHeading() ;

           if (distance(obj.Data(pos,obj.Experiment.X ),0 , obj.Data(pos,obj.Experiment.Y),0) >.1)
               error ('this is not a proper final heading file. Results may be inacurate')
           end
       end
       
       
       %determines the last heading in the file to be used as the direction
       %the subject thought the startign poitn was.
       function [final_heading, pos] = GetFinalHeading(obj)
            pos = length(H);
            while isnan(obj.Data(pos,obj.Experiment.H))
                pos = pos-1;
            end   
            final_heading =  obj.Data(pos,obj.Experiment.H);

       end
       
       
       %OBSOLETE OR NOT IMPLEMENTED
       %used to get a random set of turn info. not used
       function list = GetAngles(this)
           list = this.TurnA.GetAllTurnInfo();
       end

       %OBSOLETE: 
       %function, used to be used for determining trial number
       %when VPN naming scheme was different. Trial is no longer this
       %complicated due to current scheme so not needed.
       function t = GetTrial(this)
           t= 0;
           if strcmp(this.Trial, 'exp') || strcmp(this.Trial, 'EXP')
               t = -1;
           else
               t = sscanf(this.Trial, '%f');
           end           
       end
        
        
   end
end


% OLD CODE GOES HERE

    %function obj = SetMeta(obj)           
    %       file = java.lang.String(obj.FileName);
    %       meta =file.substring(0, file.indexOf('['));
           
           
           
    %       %get the subject number
    %       obj.Subject = char(meta.substring(0, meta.indexOf('_')));
    %       meta = meta.substring(meta.indexOf('_')+1);
           
           %get the conditions 
    %       obj.Condition = char(meta.substring(0, meta.lastIndexOf('_')));
           
           %obj.Maze = char(file.substring(0, file.indexOf('_')));
           %file = file.substring(file.indexOf('_')+1);
           
           % get the task
           %obj.Task = char(file.substring(0, file.indexOf('_')));
           %file = file.substring(file.indexOf('_')+1);
           
           %get the Ball Position
           %obj.Ball = char(file.substring(0, file.indexOf('_')));
           %file = file.substring(file.indexOf('_')+1);
           
           %get the trial
           %obj.Trial = char(file.substring(0, file.indexOf('['))); 
          
    %       obj.Trial = char(meta.substring(meta.lastIndexOf('_')+1, meta.length()));
           
    %   end



